/*!
 * FileName: luogu-1198.cpp
 * This Problem is on luogu. The ID of the problem is 1198. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include <cstdio>
#include <iostream>
#include <malloc.h>
#include <cmath> 
#include <cstdio>
#include <algorithm>
const int inf = 0x7fffffff;
using namespace std;
int D;
struct Node{
    int S;
    Node *lson, *rson;
};
void updata(Node *tree)
{
    tree -> S = max(tree -> lson -> S ,tree -> rson -> S) %D;
}
void build(Node *tree, int x, int y)
{
    if(x == y)
    {
        int tmp = -inf;
        tree -> S = tmp;
        return;
    }
    tree -> lson = (Node*)malloc(sizeof(Node));
    tree -> rson = (Node*)malloc(sizeof(Node));
    int mid = (x + y) >> 1;
    build(tree -> lson, x, mid);
    build(tree -> rson, mid+1, y);
    updata(tree);
}
void change(Node *tree, int x, int val, int nowl, int nowr)
{
    if(nowl == x && x == nowr)
    {
        tree -> S = val % D;
        return;
    }
    int mid = (nowl + nowr) >> 1;
    if(x<=mid) change(tree -> lson, x, val, nowl, mid);
    if(x > mid) change(tree -> rson, x, val, mid+1, nowr);
    updata(tree);   
}
int query(Node *tree, int x, int y, int nowl, int nowr)
{
    if(x <= nowl and nowr<= y)
        return tree -> S;
    int mid = (nowl + nowr) >> 1;
    int ans = -inf;
    if(x <= mid) ans = max(ans, query(tree -> lson, x, y, nowl, mid));
    if(y > mid) ans = max(ans,query(tree -> rson, x, y, mid+1, nowr));
    return ans % D;
}
int main()
{
    Node *root=(Node*)malloc(sizeof(Node));
    int n = 200000, m;
    scanf("%d%d", &m, &D);
    build(root, 1, n);
	int t = 0;
	int L = 0;
    for(register int i=1; i <= m; i++)
    {
        char op;
        cin >> op;
        if(op == 'A')
        {
            int x, k ;
            scanf("%d",&k); k += t;
            change(root, ++L, k, 1, n);
        }
        else
        {
            int x;
            scanf("%d", &x);
            printf("%d\n", t = query(root, L - x + 1, L, 1, n) % D);
        }
    }
    // system("pause");
    return 0;
}

//int main()
//{
//	null = malloc_();
//	int D, m;
//	scanf("%d%d", &m, &D);
//	Node * root = malloc_();
//	build(root, 1, _N);
//	puts("build Done");
//	int t = 0;
//	int L = 0;
//	for(register int i = 1;i <= m;i++)
//	{
//		int op;
////		scanf("%d", &op);
////		if(op == 2)
////		{
////			int x, y;
////			scanf("%d%d", &x, &y);
////			printf("In [%d, %d] Min Val = %d\n", x, y, query(root, x, y, 1, n));
////		}
////		else
////		{
////			int x, y, val;
////			scanf("%d%d%d", &x, &y, &val);
////			change(root, x, y, val, 1, n);
////		}
//		char ch;
//		cin >> ch;
//		if(ch == 'A')
//		{
//			int val;
//			scanf("%d", &val);
//			val += t;
//			printf("Add %d\n", val);
//			change(root, L + 1, L + 1, val, 1, _N);
//		}
//		else
//		{
//			int val;
//			scanf("%d", &val);
//			printf("%d\n", query(root, L - val + 1, L, 1, _N)) ;
//		} 
//	}
//	puts("0");
//	return 0;
//}
